package com.sdkj.service.base.quartz;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sdkj.dao.DaoSupport;
import com.sdkj.entity.ScheduleJob;
import com.sdkj.util.PageData;


@Service("scheduleJobService")
public class ScheduleJobService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	/*
	* 新增
	*/
	public void save(ScheduleJob job)throws Exception{
		//添加数据库
		PageData pd = new PageData();
		pd.put("job_id", job.getJobId());
		pd.put("job_name", job.getJobName());
		pd.put("job_group", job.getJobGroup());
		pd.put("job_status", job.getJobStatus());
		pd.put("method_name", job.getMethodName());
		pd.put("spring_id", job.getSpringId());
		pd.put("expression", job.getExpression());
		dao.save("ScheduleJobMapper.save", pd);
	}
	
	/*
	* 删除
	*/
	public void delete(PageData pd)throws Exception{
		dao.delete("ScheduleJobMapper.delete", pd);
	}
	
	/*
	* 通过id获取数据
	*/
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("ScheduleJobMapper.findById", pd);
	}
	
	/*
	* 修改
	*/
	public void edit(String status,String job_id)throws Exception{
		PageData pd = new PageData();
		pd.put("job_status", status);
		pd.put("job_id", job_id);
		dao.update("ScheduleJobMapper.edit", pd);
	}
	
	/*
	*列表(全部)
	*/
	public List<ScheduleJob> listAll()throws Exception{
		List<ScheduleJob> schList = new ArrayList<ScheduleJob>();
		List<PageData> list = (List<PageData>)dao.findForList("ScheduleJobMapper.listAll", null);
		for(PageData pd : list){
			ScheduleJob scheduleJob = new ScheduleJob();
			scheduleJob.setJobId(pd.getString("job_id"));
			scheduleJob.setJobName(pd.getString("job_name"));
			scheduleJob.setJobGroup(pd.getString("job_group"));
			scheduleJob.setJobStatus(pd.getString("job_status"));
			scheduleJob.setSpringId(pd.getString("spring_id"));
			scheduleJob.setMethodName(pd.getString("method_name"));
			scheduleJob.setExpression(pd.getString("expression"));
			schList.add(scheduleJob);
		}
		return schList;
	}
}

